package com.hvgroup.base.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor(access = lombok.AccessLevel.PRIVATE)
public enum TaskStatus {
    FAILED(-1, "失败"),
    ABORTED(-2, "中止"),
    TIMEOUT(-3, "超时"),

    SUCCESS(0, "成功"),

    PENDING(1, "未开始"),
    RUNNING(2, "运行中"),
    PAUSED(3, "暂停"),
    WAITING(4, "等待");

    private final int code;
    private final String label;

    public boolean isSuccess() {
        return code == 0;
    }

    public boolean isFailure() {
        return code < 0;
    }

    public boolean isPending() {
        return code == 1;
    }

    public boolean isRunning() {
        return code >= 2;
    }

    public static TaskStatus fromCode(int code) {
        for (TaskStatus s : values()) {
            if (s.code == code) return s;
        }
        throw new IllegalArgumentException("未知状态码: " + code);
    }
}
